package communication.game;

import game.*;
import game.Game.Status;


import communication.ComCliSrv;

import server.ServerInternals;
/**
 * Objet envoye au serveur pour demarrer une partie
 * @author Jonathan Gander, Laurent Constantin
 * @version 1
 */
public class StartGame extends ComCliSrv {
	
	private static final long serialVersionUID = 1560463043213776202L;
	
	private final Game game;
	
	/**
	 * Constructeur
	 * @param game La partie
	 */
	public StartGame (Game game){
		this.game = game;
	} 

	/**
	 * Permet de demarrer une partie sur le serveur
	 */
	public void handleServerInternals(ServerInternals internals) {
				
		internals.startGame(game.getId());
		internals.getGame(game.getId()).setStatus(Status.STARTED);
		
		ServersideGame ssg = internals.getGame(game.getId());
		ssg.initializePlayers();
		MinimalGame mg = new MinimalGame(game);
		
		
		internals.sendDataToClients(ssg.getPlayersSockets(), 
				new GameStarted(mg,ssg.getPlayersAsPlayer()));

		internals.sendGameList();
	}
}
